import { req_goodsDetail_data } from '../../api/req_fun'
import { Message } from 'element-ui'
export default {
    namespaced: true,
    state: () => ({
        goodsDetail_obj: {}
    }),
    actions: {
        async get_goodsDetail_obj({ commit }, id) {
            const data = await req_goodsDetail_data(id)
            if (data.code >= 200 && data.code < 300) {
                commit('GET_GOODSDETAIL_OBJ', data.data);
            } else {
                Message.error('请求失败!')
            }
        }
    },
    mutations: {
        GET_GOODSDETAIL_OBJ(state, data) {
            state.goodsDetail_obj = data;
        }
    },
    getters: {
        top_title_list(state) {
            let arr = [];
            let k
            for (k in state.goodsDetail_obj.categoryView) {
                if (typeof (state.goodsDetail_obj.categoryView[k]) === "string") {
                    arr.push(state.goodsDetail_obj.categoryView[k])
                }
            }
            return arr
        },
        goodInfo(state) {
            return state.goodsDetail_obj.skuInfo? state.goodsDetail_obj.skuInfo : {}
        },
        spuSaleAttrList(state) {
            return state.goodsDetail_obj.spuSaleAttrList || []
        }
    }
}